/* rehash --- a decentralised hash<->hash store
   Copyright © 2020 Maxime Devos <maxime.devos@student.kuleuven.be>

   This file is part of rehash.

   rehash is free software; you can redistribute it and/or modify it
   under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3 of the License, or (at
   your option) any later version.

   rehash is distributed in the hope that it will be useful, but
   WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with rehash.  If not, see <http://www.gnu.org/licenses/>. */

/**
 * @brief Some hash manipulation
 * @author Maxime Devos
 */

#ifndef REHASH_UTIL_H
#define REHASH_UTIL_H

#include "rehash_types.h"

#ifdef __cplusplus
extern "C"
{
#if 0
}
#endif
#endif

/**
 * Convert a given name of a hash to to our internal
 * representation.
 *
 * @param name human readable string (e.g. sha256), NUL-terminated
 * @return the hash type on success, #REHASH_HASH_NONE on error
 */
enum REHASH_Hash_Type
REHASH_parse_hashtype_string (const char *name);

/**
 * How long is the string representation of the hash
 * type? (including terminating NUL byte)
 *
 * @param internal representation (#REHASH_HASH_NONE is invalid!)
 * @return the length on success (>0, <=32), 0 if not recognised
 */
int
REHASH_hashtype_strsize (enum REHASH_Hash_Type type);

/**
 * Write a human readable representation of a hash type.
 *
 * If the output buffer is too small, only a partial write
 * is performed.
 *
 * @param type hash type to figure out a string of
 * @param size size of output buffer
 * @param outbuf location to write output, including terminating NUL byte
 * @return the size of the actual string (including NUL byte), or 0
 *  if type is unrecognised
 */
int
REHASH_unparse_hashtype (enum REHASH_Hash_Type type, int size, char outbuf[]);

#if 0
{
#endif
#ifdef __cplusplus
}
#endif

#endif
